﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using service;
using model;
namespace Trathat
{
    public partial class ChitietSanphamTrathat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string s = Request.QueryString["Loai"];
            string id = Request.QueryString["ID"];
            if (s == "1")
                lblOrder.Text = "Sản phẩm > Trà cụ";
            else
                lblOrder.Text = "Sản phẩm > Trà";

            List<SanphamTrathatModel> lisSanpham = new List<SanphamTrathatModel>();
            lisSanpham = new SanphamTrathatService().getListSanphamByID(Convert.ToInt64(id));
            if (lisSanpham.Count > 0)
            {
                if (s == "1")
                    lblOrder.Text = "Sản phẩm > Trà cụ > " + lisSanpham[0].Tensanpham;
                else
                    lblOrder.Text = "Sản phẩm > Trà > " + lisSanpham[0].Tensanpham;
            }

            listSanpham.DataSource = new SanphamTrathatService().getListSanphamByID(Convert.ToInt64(s));
            listSanpham.DataBind();
            getistSanphamKhac(s);
            getListImageBySanpham(id);
        }

        private void getistSanphamKhac(string s)
        {
            List<SanphamTrathatModel> lisSP = new List<SanphamTrathatModel>();
            lisSP = new SanphamTrathatService().getListSanphamByLoai(Convert.ToInt64(s));
            for (int i=0; i < lisSP.Count; i++)
            {
                if (lisSP[i].ID == Convert.ToInt64(s))
                {
                    lisSP.RemoveAt(i);
                    break;
                }
            }
            RadListView1.DataSource = lisSP;
            RadListView1.DataBind();
        }

        private void getListImageBySanpham(string id)
        {
            listHinhanh.DataSource = new ImageService().getListImageBySanpham(Convert.ToInt64(id));
            listHinhanh.DataBind();
        }
    }
}